import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { SQuestionData } from "../../../../Message/Public/SQuestionData";
import { EQuestionFuncCode } from "../../../../Message/Public/EQuestionFuncCode";
import { QuestionDataTool } from "./QuestionDataTool";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SQuestion } from "../../../../Message/Public/SQuestion";
import { _num } from "../../../../this/_num";
import { _funcCode } from "../../../../this/_funcCode";
type int = number;
//class QuestionDatePanel
    
    export  class QuestionDatePanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._normalTf = new GTextFormat("", 14, 16777215);
            this._rightTf = new GTextFormat("", 14, 16776960);
            this._wrongTf = new GTextFormat("", 14, 65280);
            this._cbA = ObjCreate.createCheckBox("A", 0, 0, 300, 20, this, "GCheckBoxQStyle");
            this._cbB = ObjCreate.createCheckBox("B", 0, 40, 300, 20, this, "GCheckBoxQStyle");
            this._cbC = ObjCreate.createCheckBox("C", 0, 80, 300, 20, this, "GCheckBoxQStyle");
            this._cbD = ObjCreate.createCheckBox("D", 0, 120, 300, 20, this, "GCheckBoxQStyle");
            addEventListener(flash.events.Event.CHANGE, this.onCbChangeHandler);
            this._right = new Object /* flash.display.Bitmap */();
            this._rightBg = new Object /* flash.display.Bitmap */();
            this._wrong = new Object /* flash.display.Bitmap */();
            this._wrongBg = new Object /* flash.display.Bitmap */();
            LoaderHelp.addResCallBack("question", this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._right.bitmapData = GlobalClass.getBitmapData(ImagesConst.q_right);
            this._rightBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.q_rightBg);
            this._wrong.bitmapData = GlobalClass.getBitmapData(ImagesConst.q_wrong);
            this._wrongBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.q_wrongBg);
            return;
        }

        public get funcCode(): int
        {
            return this._funcCode;
        }

        public updateQuestion(arg1: SQuestionData): void
        {
            this._num = arg1.num;
            this._sQuestion = arg1.question;
            this._cbA.label = this._sQuestion.a;
            this._cbB.label = this._sQuestion.b;
            this._cbC.label = this._sQuestion.c;
            this._cbD.label = this._sQuestion.d;
            this._cbA.textField.setTextFormat(this._normalTf);
            this._cbB.textField.setTextFormat(this._normalTf);
            this._cbC.textField.setTextFormat(this._normalTf);
            this._cbD.textField.setTextFormat(this._normalTf);
            this.setVisible(true);
            this._selectedCb = null;
            this._wrongCb = null;
            this._funcCode = 0;
            return;
        }

        public setFuncCode(arg1: int): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            this._funcCode = arg1;
            var loc5=arg1;
            switch (loc5) 
            {
                case EQuestionFuncCode._EQuestionFuncCodeRight:
                {
                    loc1 = QuestionDataTool.correctFuncTimes;
                    if (loc1 > 0) 
                    {
                        this.setVisible(false);
                        loc5 = QuestionDataTool.getCorrectAnswer();
                        switch (loc5) 
                        {
                            case this._sQuestion.a:
                            {
                                loc2 = this._cbA;
                                break;
                            }
                            case this._sQuestion.b:
                            {
                                loc2 = this._cbB;
                                break;
                            }
                            case this._sQuestion.c:
                            {
                                loc2 = this._cbC;
                                break;
                            }
                            case this._sQuestion.d:
                            {
                                loc2 = this._cbD;
                                break;
                            }
                        }
                        if (loc2 == null) 
                        {
                            return;
                        }
                        this._selectedCb = loc2;
                        loc2.visible = true;
                        if (QuestionDataTool.answerState == 1) 
                        {
                            this.correctFunction();
                        }
                    }
                    else 
                    {
                        this._funcCode = 0;
                    }
                    break;
                }
                case EQuestionFuncCode._EQuestionFuncCodeRemainTwo:
                {
                    loc1 = QuestionDataTool.remainTwoFuncTimes;
                    if (loc1 > 0) 
                    {
                        this.setVisible(false);
                        loc3 = [];
                        loc5 = QuestionDataTool.getCorrectAnswer();
                        switch (loc5) 
                        {
                            case this._sQuestion.a:
                            {
                                loc2 = this._cbA;
                                loc3.push(this._cbB);
                                loc3.push(this._cbC);
                                loc3.push(this._cbD);
                                break;
                            }
                            case this._sQuestion.b:
                            {
                                loc2 = this._cbB;
                                loc3.push(this._cbA);
                                loc3.push(this._cbC);
                                loc3.push(this._cbD);
                                break;
                            }
                            case this._sQuestion.c:
                            {
                                loc2 = this._cbC;
                                loc3.push(this._cbA);
                                loc3.push(this._cbB);
                                loc3.push(this._cbD);
                                break;
                            }
                            case this._sQuestion.d:
                            {
                                loc2 = this._cbD;
                                loc3.push(this._cbA);
                                loc3.push(this._cbB);
                                loc3.push(this._cbC);
                                break;
                            }
                        }
                        if (loc2 == null) 
                        {
                            return;
                        }
                        loc4 = Math.round(2 * Math.random());
                        this._wrongCb = loc3[loc4] as GCheckBox;
                        this._wrongCb.visible = true;
                        loc2.visible = true;
                    }
                    else 
                    {
                        this._funcCode = 0;
                    }
                    break;
                }
                case EQuestionFuncCode._EQuestionFuncCodeDouble:
                {
                    loc1 = QuestionDataTool.doubleFuncTimes;
                    if (loc1 <= 0) 
                    {
                        this._funcCode = 0;
                    }
                    break;
                }
            }
            QuestionDataTool.functCode = this._funcCode;
            return;
        }

        public setCheckBoxEnable(): void
        {
            var loc1=false;
            if (QuestionDataTool.answerState == 1) 
            {
                loc1 = true;
            }
            this._cbA.enabled = loc1;
            this._cbB.enabled = loc1;
            this._cbC.enabled = loc1;
            this._cbD.enabled = loc1;
            this._cbA.selected = false;
            this._cbB.selected = false;
            this._cbC.selected = false;
            this._cbD.selected = false;
            return;
        }

        public showResult(): void
        {
            var loc1=null;
            var loc3=null;
            if (QuestionDataTool.selectAnswer == "" && !(QuestionDataTool.answerState == 2)) 
            {
                return;
            }
            loc1 = this._right;
            var loc2=new Object /* flash.display.Bitmap */();
            if (QuestionDataTool.isCorrect()) 
            {
                loc2 = this._rightBg;
            }
            else 
            {
                loc2 = this._wrongBg;
            }
            var loc4=QuestionDataTool.getCorrectAnswer();
            switch (loc4) 
            {
                case this._sQuestion.a:
                {
                    loc3 = this._cbA;
                    break;
                }
                case this._sQuestion.b:
                {
                    loc3 = this._cbB;
                    break;
                }
                case this._sQuestion.c:
                {
                    loc3 = this._cbC;
                    break;
                }
                case this._sQuestion.d:
                {
                    loc3 = this._cbD;
                    break;
                }
            }
            if (loc3 == null) 
            {
                return;
            }
            loc1.x = loc3.x + loc3.textField.textWidth + 20;
            loc1.y = loc3.y - 10;
            loc2.x = 240;
            loc2.y = 100;
            addChild(loc1);
            addChild(loc2);
            if (this._selectedCb == null) 
            {
                return;
            }
            this._selectedCb.selected = true;
            return;
        }

        public removeResult(): void
        {
            if (this._right && this._right.parent) 
            {
                removeChild(this._right);
            }
            if (this._rightBg && this._rightBg.parent) 
            {
                removeChild(this._rightBg);
            }
            if (this._wrong && this._wrong.parent) 
            {
                removeChild(this._wrong);
            }
            if (this._wrongBg && this._wrongBg.parent) 
            {
                removeChild(this._wrongBg);
            }
            return;
        }

        public correctFunction(): void
        {
            var loc1=null;
            var loc2=null;
            if (this._funcCode == EQuestionFuncCode._EQuestionFuncCodeRight) 
            {
                this._selectedCb.enabled = false;
                this._selectedCb.selected = true;
                loc1 = this._selectedCb.label;
                QuestionDataTool.selectAnswer = loc1;
                loc2 = {"num": _num, "questionId": this._sQuestion.questionId, "answer": loc1, "funcCode": _funcCode};
                Dispatcher.dispatchEvent(new DataEvent(EventName.AnswerQuestion, loc2));
                QuestionDataTool.haveAnswer = true;
            }
            return;
        }

        public wrongFunction(): void
        {
            var loc1={"num": _num, "questionId": this._sQuestion.questionId, "answer": this._wrongCb.label, "funcCode": _funcCode};
            Dispatcher.dispatchEvent(new DataEvent(EventName.AnswerQuestion, loc1));
            QuestionDataTool.haveAnswer = true;
            return;
        }

        /* internal  */onCbChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._cbA.enabled = false;
            this._cbB.enabled = false;
            this._cbC.enabled = false;
            this._cbD.enabled = false;
            var loc1="";
            this._selectedCb = arg1.target as GCheckBox;
            this._selectedCb.selected = true;
            loc1 = this._selectedCb.label;
            QuestionDataTool.selectAnswer = loc1;
            var loc2={"num": _num, "questionId": this._sQuestion.questionId, "answer": loc1, "funcCode": _funcCode};
            Dispatcher.dispatchEvent(new DataEvent(EventName.AnswerQuestion, loc2));
            QuestionDataTool.haveAnswer = true;
            return;
        }

        /* internal  */setVisible(arg1: Boolean): void
        {
            this._cbA.visible = arg1;
            this._cbB.visible = arg1;
            this._cbC.visible = arg1;
            this._cbD.visible = arg1;
            return;
        }

        /* internal */ /* var */_cbA: GCheckBox;

        /* internal */ /* var */_cbB: GCheckBox;

        /* internal */ /* var */_cbC: GCheckBox;

        /* internal */ /* var */_cbD: GCheckBox;

        /* internal */ /* var */_normalTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_rightTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_wrongTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_num: int;

        /* internal */ /* var */_sQuestion: SQuestion;

        /* internal */ /* var */_funcCode: int=0;

        /* internal */ /* var */_wrong: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_wrongBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_right: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rightBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_selectedCb: GCheckBox;

        /* internal */ /* var */_wrongCb: GCheckBox;
    }
